Page({
    data: {
        taps: [{
            id: 0,
            value: "体验问题",
            isActive: true
        },
        {
            id: 1,
            value: "商品丶商家投诉",
            isActive: false
        },
        ],
        chooseImage: [],
        textVal: '',
        upLoadImgs: []
    },
    handleTapsItemChange(e) {
        let index = e.detail.index
        let {
            taps
        } = this.data
        taps.forEach((v, i) => i === index ? v.isActive = true : v.isActive = false)
        this.setData({
            taps
        })
    },
    handleImageChoose() {
        wx.chooseImage({
            count: 9,
            sizeType: ['original', 'compressed'],
            sourceType: ['album', 'camera'],
            success: (result) => {
                this.setData({
                    chooseImage: [...this.data.chooseImage, ...result.tempFilePaths]
                })

            }
        });
    },
    handleRemoveImg(e) {


        const { index } = e.currentTarget.dataset
        let { chooseImage } = this.data
        chooseImage.splice(index, 1)
        this.setData({
            chooseImage
        })
    },
    handleTextInput(e) {
        this.setData({
            textVal: e.detail.value
        })
    },
    handleFormSubmit() {
        const { textVal, chooseImage } = this.data
        if (!textVal.trim()) {
            wx.showToast({
                title: '输入不合法',
                icon: 'none',
                image: '',
                duration: 1500,
                mask: true,
            });
            reyurn;
        }
        wx.showLoading({
            title: '正在上传中',
            mask: true,
        });
        if (!chooseImage.length === 0) {
            chooseImage.forEach((v, i) => {
                wx.uploadFile({
                    url: 'https://images.ac.cn/api/upload/upload',
                    filePath: v,
                    name: 'file',
                    formData: {},
                    success: (result) => {
                        console.log(result);
                        let url = json.parse(result.data).url;
                        this.upLoadImgs.push(url)
                        if (i === chooseImage.length - 1) {
                            this.setData({
                                textVal: '',
                                chooseImgs: []
                            })

                            wx.navigateBack({
                                dalta: 1
                            })
                        }

                    },
                });
            })
        } else {
            wx.hideLoading();
            console.log("只是提交了文本");
        }


    }
})